package com.tudouji.project.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.tudouji.project.system.mapper.UpimageMapper;
import com.tudouji.common.utils.IdUtils;
import com.tudouji.project.system.domain.SysUser;
import com.tudouji.project.system.domain.Upimage;
import com.tudouji.project.system.service.IUpimageService;

/**
 * 上传图片Service业务层处理
 * 
 * @author tudouji
 * @date 2021-05-12
 */
@Service
public class UpimageServiceImpl implements IUpimageService {
	@Autowired
	private UpimageMapper upimageMapper;

	/**
	 * 查询上传图片
	 * 
	 * @param guid
	 *            上传图片ID
	 * @return 上传图片
	 */
	@Override
	public Upimage selectUpimageById(String guid) {
		return upimageMapper.selectUpimageById(guid);
	}

	/**
	 * 查询上传图片列表
	 * 
	 * @param upimage
	 *            上传图片
	 * @return 上传图片
	 */
	@Override
	public List<Upimage> selectUpimageList(Upimage upimage) {
		return upimageMapper.selectUpimageList(upimage);
	}

	/**
	 * 新增上传图片
	 * 
	 * @param upimage
	 *            上传图片
	 * @return 结果
	 */
	@Override
	public int insertUpimage(Upimage upimage) {
		return upimageMapper.insertUpimage(upimage);
	}

	/**
	 * 修改上传图片
	 * 
	 * @param upimage
	 *            上传图片
	 * @return 结果
	 */
	@Override
	public int updateUpimage(Upimage upimage) {
		return upimageMapper.updateUpimage(upimage);
	}

	/**
	 * 批量删除上传图片
	 * 
	 * @param guids
	 *            需要删除的上传图片ID
	 * @return 结果
	 */
	@Override
	public int deleteUpimageByIds(String[] guids) {
		return upimageMapper.deleteUpimageByIds(guids);
	}

	/**
	 * 删除上传图片信息
	 * 
	 * @param guid
	 *            上传图片ID
	 * @return 结果
	 */
	@Override
	public int deleteUpimageById(String guid) {
		return upimageMapper.deleteUpimageById(guid);
	}

	@Override
	public String insertUpimage(MultipartFile file, String filePath, String fileName) {
		String guid=IdUtils.fastSimpleUUID();
		Upimage img = new Upimage();
		img.setGuid(guid);
		img.setUrl(fileName);
		img.setImagename(file.getOriginalFilename());
        this.insertUpimage(img);
        return guid;
	}
}
